<h1>编辑产品</h1>
<form name="userForm" novalidate>
    <div class="form-group" show-errors>
        <label class="control-label">编码</label>
        <input type="text" class="form-control" name="code" ng-model="production.code" required placeholder="编码"/>
        <p class="help-block" ng-if="userForm.code.$error.required">必填</p>
    </div>
    <div class="form-group" show-errors>
        <label class="control-label">产品名称</label>
        <input type="text" class="form-control" name="name" ng-model="production.name" required placeholder="名称"/>
        <p class="help-block" ng-if="userForm.name.$error.required">必填</p>
    </div>

    <div class="form-group">
        <label class="control-label">序号</label>
        <input type="number" class="form-control" name="seq" ng-model="production.seq" placeholder="序号"/>
    </div>

    <div class="form-group">
        <label class="control-label">产品价格</label>
        <input type="number" class="form-control" name="cost" ng-model="production.cost" placeholder="价格"/>
    </div>

    <div class="form-group">
        <label class="control-label">产品库存</label>
        <input type="number" class="form-control" name="stock" ng-model="production.stock" placeholder="库存"/>

        <div class="checkbox">
            <label class="checkbox di">
                <input type="checkbox" ng-model="production.showStock"> 显示库存
            </label>
        </div>

    </div>


    <div class="form-group">
        <label class="control-label">产品分类</label>
        <div class="radio">
            <label class="radio di">
                <input type="radio" ng-model="production.type" value="0"> 虚拟商品
            </label>
            <label class="radio di ml5">
                <input type="radio" ng-model="production.type" value="1"> 实物商品
            </label>
      </div>
    </div>

    <div class="form-group">
        <label class="control-label">产品图</label>
        <!--<div class="col-sm-10">-->
        <file-upload class="dib ml20" title="添加照片" on-success="appendImg(url)"></file-upload>
        <!--</div>-->
        <div>
            <ul ng-sortable="galleryConfig" class="row list-unstyled sortable" id="js-photo-grid">
                <li class="col-4 row-space-4 " draggable="true" style="display:inline-block;width:30%;"
                    ng-repeat="img in production.images track by $index">
                    <div class="panel photo-item">
                        <img style="width: 100%; height: 150px" ng-src="{{img}}" class="img-responsive-height">
                    </div>
                </li>

            </ul>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label">分类</label>
        <div class="dib ml5">
            <div ng-repeat="p in production.classification track by $index" class="tag label btn-info lg dib">
                <span>{{classificationObject[p].name}}</span><a ng-click="remove(p, production.classification)">
                <i class="remove ml2 cp glyphicon glyphicon-remove-sign glyphicon-white"></i></a>
            </div>
            <a class="btn btn-primary btn-xs ml10" ng-init="showClass=false" ng-click="showClass = !showClass"><span
                    class="glyphicon glyphicon-plus"></span></a>
        </div>

        <div ui-tree id="tree-root" ng-show="showClass" data-nodrop-enabled="true">
            <ol ui-tree-nodes ng-model="classifications">
                <li ng-repeat="node in classifications" ui-tree-node ng-include="'nodes_renderer.html'"></li>
            </ol>
        </div>

    </div>

    <div class="form-group">
        <label class="control-label">属性</label>
        <div>
            <select class="form-control dib ltw"  ng-model="selectPropertyGroup">
                <option ng-if="o.type=='1'" ng-repeat="o in properties" value="{{o.objectId}}">{{o.name}}</option>
            </select>
            <a class="btn btn-primary btn-xs ml10"ng-click="addPropertyGroup(selectPropertyGroup)">添加属性组</a>
        </div>

        <div class="mt2">
            <select class="form-control dib ltw"  ng-model="selectProperty">
                <option ng-if="o.type=='0'" ng-repeat="o in properties" value="{{o.name}}">{{o.name}}</option>
            </select>
            <a class="btn btn-primary btn-xs ml10" ng-click="addProperty(selectProperty)">添加属性</a>
        </div>
        <div class="mt5" ng-repeat="p in production.properties track by $index">{{p.key}} : <input ng-model="p.value">
            <a ng-click="remove(p, production.properties)">
                <i class="remove ml2 cp glyphicon glyphicon-remove-sign glyphicon-white"></i></a>
        </div>
    </div>



    <div class="form-group">
        <label class="control-label">库存规格 <a class="btn btn-primary btn-xs ml10"ng-click="addSku()"><span
                class="glyphicon glyphicon-plus"></span></a></label>

        <div class="mt5">
            <div ng-repeat="sku in production.skus" class="mb5">
                <label class="mr2">规格名:</label><input ng-model="sku.name" placeholder="规格名"><a ng-click="remove(sku, production.skus)">
                <i class="remove ml2 cp glyphicon glyphicon-remove-sign glyphicon-white"></i></a>
                <label class="mr2">规格值:</label><div  ng-repeat="spec in sku.spec  track by $index"class="dib">
                <input class="ml2" ng-model="spec.name" placeholder="规格值">
                <a ng-click="remove(spec, sku.spec)">
                <i class="remove ml2 cp glyphicon glyphicon-remove-sign glyphicon-white"></i></a>
                </div>
                <a class="btn btn-primary btn-xs ml10" ng-click="addSkuSpec(sku.spec)"><span class="glyphicon glyphicon-plus"></span></a>
            </div>
        </div>
    </div>

    <button class="btn btn-primary" ng-click="generateSkuDetail()">生成库存规格具体信息</button>

    <div class="form-group mt5">
        <label class="control-label">库存规格对应信息</label>
        <div class="mt1">
            <div ng-repeat="skuDetail in production.skuDetail" class="mb5">
                <label class="mr2">{{skuDetail.name}}</label>
                <label class="mr2">编码:</label><input ng-model="skuDetail.code" placeholder="编码">
                <label class="mr2">库存:</label><input ng-model="skuDetail.stock" placeholder="库存">
                <label class="mr2">价格:</label><input ng-model="skuDetail.cost" placeholder="价格">
                <label class="mr2">期数:</label><input ng-model="skuDetail.num" placeholder="期数">
                <label class="mr2">照片:</label><img ng-src="{{skuDetail.img}}" style="width: 64px; height: 64px;"><file-upload class="dib ml20" title="添加照片" on-success="appendSkuImg(url, skuDetail)"></file-upload>
            </div>
        </div>
    </div>


    <div class="form-group">
        <label class="control-label">运费</label>
        <input type="number" class="form-control" name="freight" ng-model="production.freight"  ng-min="0" placeholder="运费 0即为包邮"/>
        <div class="mt5">满<input type="number" class="form-control dib" style="width: 10%" name="freeFreightCost" ng-model="production.freeFreightCost" ng-min="0" placeholder=""/>元包邮</div>
    </div>

    <div class="form-group">
        <label class="control-label">限购</label>
        <input type="number" class="form-control" name="limitBuy"  ng-model="production.limitBuy" placeholder="每人限购"/>
    </div>


    <div class="form-group">
        <label class="control-label">是否保修</label>
        <div class="radio">
            <label class="radio di">
                <input type="radio" ng-model="production.guarantee" value="0"> 保修
            </label>
            <label class="radio di ml5">
                <input type="radio" ng-model="production.guarantee" value="1"> 不保修
            </label>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label">是否提供发票</label>
        <div class="radio">
            <label class="radio di">
                <input type="radio" ng-model="production.bill" value="0"> 是
            </label>
            <label class="radio di ml5">
                <input type="radio" ng-model="production.bill"  value="1"> 否
            </label>
        </div>
    </div>



    <div class="form-group">
        <label class="control-label">会员折扣</label>
        <div class="radio">
            <label class="radio di">
                <input type="radio" ng-model="production.discount" value="0"> 是
            </label>
            <label class="radio di ml5">
                <input type="radio" ng-model="production.discount"  value="1"> 否
            </label>
        </div>
    </div>


    <div class="form-group" >
        <label class="control-label">产品简介</label>
        <textarea row="3" type="text" class="form-control" name="summary" ng-model="production.summary" placeholder="简介">
        </textarea>
    </div>


    <div class="form-group">
        <label class="control-label">详细介绍</label>
        <div ckeditor="options" ng-model="production.detail" ready="onReady()"></div>
    </div>



    <div class="form-group">
        <label class="control-label db">产品标签</label>
        <input type="text" class="form-control ltw dib" name="tag" ng-model="editTag" placeholder="标签名"/>
        <a class="btn btn-primary btn-xs ml10" ng-click="addTags(editTag)"><span
                class="glyphicon glyphicon-plus"></span></a>
        <div class="mt5">
            <div ng-repeat="p in production.tags track by $index" class="tag label btn-info lg dib">
                <span>{{p}}</span><a ng-click="remove(p, production.tags)">
                <i class="remove ml2 cp glyphicon glyphicon-remove-sign glyphicon-white"></i></a>
            </div>
        </div>
    </div>

    <div class="form-group">
        <label class="control-label db">关联产品:</label>
        <ng-autocomplete class="ltw" ng-model="editRelation"
                         show-property="name"
                         delay="300"
                         theme="blue"
                         init-text=""
                         get-result="searchProduction(keyword)"
                         placeholder="搜索产品">
        </ng-autocomplete>
        <a class="btn btn-primary btn-xs ml10" ng-click="addRelation(editRelation)"><span
                class="glyphicon glyphicon-plus"></span></a>
        <div class="mt5">
            <div ng-repeat="p in production.relation track by $index" class="tag label btn-info lg dib">
                <span>{{p.name}}</span><a ng-click="remove(p, production.relation)">
                <i class="remove ml2 cp glyphicon glyphicon-remove-sign glyphicon-white"></i></a>
            </div>
        </div>
    </div>







    <div class="form-group">
        <label class="control-label">开售时间</label>
        <div class="radio">
            <label class="radio di">
                <input type="radio" ng-model="production.saleNow" value="0"> 立即开售
            </label>
            <label class="radio di ml5">
                <input type="radio" ng-model="production.saleNow"  value="1"> 定时开售
            </label>
        </div>

        <div ng-show="production.saleNow =='1'">
            <div class="col-sm-6" style="height:130px;">
                <div class="form-group">
                    <div  datetimepicker id="dt" ng-model="production.saleTime"  class='input-group date'>
                        <input type='text'  class="form-control" />
                    <span class="input-group-addon">
                    <span class="fa fa-calendar">
                    </span>
                   </span>
                    </div>
                </div>
            </div>
        </div>
    </div>


    <script type="text/ng-template" id="nodes_renderer.html">
        <div data-nodrag ui-tree-handle class="tree-node tree-node-content">
            <a class="btn btn-success btn-xs" ng-if="node.nodes && node.nodes.length > 0"  ng-click="toggle(this)"><span
                    class="glyphicon"
                    ng-class="{
          'glyphicon-chevron-right': collapsed,
          'glyphicon-chevron-down': !collapsed
        }"></span></a>
            {{node.name}}
               <label data-nodrag class="checkbox di cp ml20">
                    <input type="checkbox" ng-change="handleCCheck(node,node.check)" ng-model="node.check" ng-checked="checkCp(node)" >
                </label>

        </div>
        <ol ui-tree-nodes="" ng-model="node.nodes" ng-class="{hidden: collapsed}">
            <li ng-repeat="node in node.nodes" ui-tree-node ng-include="'nodes_renderer.html'">
            </li>
        </ol>
    </script>


    <div class="mt20 fix">
        <button class="btn btn-primary" ng-click="save()">保存</button>
        <button class="btn btn-link" ng-click="reset()">重置</button>
    </div>

</form>